//
//  ClassificationViewController.m
//  110
//
//  Created by 沈鑫 on 16/4/13.
//  Copyright © 2016年 乔砥. All rights reserved.
//

#import "ClassificationViewController.h"
#import "ClassificationModel.h"
#import "ClassificationTableViewCell.h"
#import "RequestManager.h"
#import "PharmacyViewController.h"
#import "MJRefresh.h"
@interface ClassificationViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
@property (nonatomic, assign)BOOL tableViewYes1;
@property (nonatomic, assign)BOOL tableViewYes2;
@property (nonatomic, assign)BOOL tableViewYes3;
@property (nonatomic, assign)BOOL tableViewYes4;
@property (nonatomic, assign)BOOL show;
@property (nonatomic, assign)NSInteger row;
@property (nonatomic, strong)UITableView *tableView1;
@property (nonatomic, strong)UITableView *tableView2;
@property (nonatomic, strong)UITableView *tableView3;
@property (nonatomic, strong)NSMutableArray *oneArray;
@property (nonatomic, strong)NSMutableArray *newoneArray;
@property (nonatomic, strong)NSMutableArray *newtowArray;
@property (nonatomic, strong)NSMutableArray *newthreeArray;
@property (nonatomic, strong)NSMutableArray *towArray;

@property (nonatomic, strong)NSArray *priceArray;
@property (nonatomic, strong)NSArray *yibaoArray;
@property (nonatomic, strong)NSArray *jibenyaoArray;

@property (nonatomic, strong)NSMutableArray *newpriceArray1;
@property (nonatomic, strong)NSMutableArray *newpriceArray2;
@property (nonatomic, strong)NSMutableArray *newpriceArray3;

@property (nonatomic, strong)NSMutableArray *newyibaoArray1;
@property (nonatomic, strong)NSMutableArray *newyibaoArray2;
@property (nonatomic, strong)NSMutableArray *newyibaoArray3;

@property (nonatomic, strong)NSMutableArray *newjibenyaoArray1;
@property (nonatomic, strong)NSMutableArray *newjibenyaoArray2;
@property (nonatomic, strong)NSMutableArray *newjibenyaoArray3;

// 用来遍历的
@property (nonatomic, strong)NSMutableArray *array1;
@property (nonatomic, strong)NSMutableArray *array2;
@property (nonatomic, strong)NSMutableArray *array3;

@property (nonatomic, assign)NSInteger count1;
@property (nonatomic, assign)NSInteger count2;
@property (nonatomic, assign)NSInteger count3;

@property (nonatomic, strong)NSMutableArray *threeArray;
@property (nonatomic, strong)NSMutableArray *nameArray1;
@property (nonatomic, strong)NSMutableArray *nameArray2;
@property (nonatomic, strong)NSMutableArray *nameArray3;
@property (nonatomic, strong)NSString *url1;
@property (nonatomic, strong)NSString *url2;
@property (nonatomic, strong)NSString *url3;
@property (nonatomic, strong)UIView *headerView;
@property (nonatomic, strong)UIScrollView *myScrollerView;
@property (nonatomic, strong)UIView *lView;
// 类型视图
@property (nonatomic, strong)UIView *styleView;
@property (nonatomic, strong)UIButton *styleButton1;
@property (nonatomic, strong)UIButton *styleButton2;
@property (nonatomic, strong)UIButton *styleButton3;
// 筛选视图
@property (nonatomic, strong)UIView *screenView;
@property (nonatomic, strong)UIButton *screenButton1;
@property (nonatomic, strong)UIButton *screenButton2;
@property (nonatomic, strong)UIButton *screenButton3;
@property (nonatomic, strong)UIButton *screenButton4;
@property (nonatomic, strong)UITableView *screenTableView1;
@property (nonatomic, strong)UITableView *screenTableView2;
@property (nonatomic, strong)UITableView *screenTableView3;
@property (nonatomic, strong)UITableView *screenTableView4;

// 显示按钮
@property (nonatomic, strong)UIButton *showButton;

// 用来接受数据个数的
@property (nonatomic, assign)NSInteger myCount;

// 数据的页数
@property (nonatomic, assign)NSInteger index1;
@property (nonatomic, assign)NSInteger index2;
@property (nonatomic, assign)NSInteger index3;
@end

@implementation ClassificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = _navigationItemTitle;
    // navigation两边button 的颜色
    [self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
    // navigation字体的颜色 大写 型号
    [self.navigationController.navigationBar setTitleTextAttributes: @{NSFontAttributeName: [UIFont fontWithName:@"Arial-BoldItalicMT" size:19],
                                                                       
                                                                       
                                                                       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    _myCount = 20;
    _index1 = 0;
    _index2 = 0;
    _index3 = 0;
    _newoneArray = [NSMutableArray array];
    _newtowArray = [NSMutableArray array];
    _newthreeArray = [NSMutableArray array];
    _newpriceArray1 = [NSMutableArray array];
    _newpriceArray2 = [NSMutableArray array];
    _newpriceArray3 = [NSMutableArray array];
    _array1 = [NSMutableArray array];
    _array2 = [NSMutableArray array];
    _array3 = [NSMutableArray array];
    _newyibaoArray1 = [NSMutableArray array];
    _newyibaoArray2 = [NSMutableArray array];
    _newyibaoArray3 = [NSMutableArray array];
    _newjibenyaoArray1 = [NSMutableArray array];
    _newjibenyaoArray2 = [NSMutableArray array];
    _newjibenyaoArray3 = [NSMutableArray array];
    
    _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, 80)];
    [self.view addSubview:_headerView];
    
    _styleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH - 30, 40)];
    _styleView.backgroundColor = [UIColor yellowColor];
    [self.headerView addSubview:_styleView];
   
    _lView = [[UIView alloc]initWithFrame:CGRectMake(0, 39, (KWIDTH - 30) / 3, 1)];
    _lView.backgroundColor = [UIColor blueColor];
    [self.styleView addSubview:_lView];
    
    _styleButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    _styleButton1.frame = CGRectMake(0, 0, (KWIDTH - 30) / 3 , 39);
    [_styleButton1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _styleButton1.backgroundColor = [UIColor greenColor];
    [_styleButton1 addTarget:self action:@selector(styleButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.styleView addSubview:_styleButton1];
    
    _styleButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _styleButton2.frame = CGRectMake((KWIDTH - 30) / 3, 0, (KWIDTH - 30) / 3 , 39);
    [_styleButton2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_styleButton2 addTarget:self action:@selector(styleButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.styleView addSubview:_styleButton2];
    
    _styleButton3 = [UIButton buttonWithType:UIButtonTypeCustom];
    _styleButton3.frame = CGRectMake((KWIDTH - 30) / 3 * 2, 0, (KWIDTH - 30) / 3 , 39);
    [_styleButton3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_styleButton3 addTarget:self action:@selector(styleButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.styleView addSubview:_styleButton3];
    
     _showButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _showButton.backgroundColor = [UIColor blackColor];
    _showButton.frame = CGRectMake(KWIDTH - 30, 0, 30, 41);
    [_showButton setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    [_showButton addTarget:self action:@selector(showAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:_showButton];
    
    _screenView = [[UIView alloc]initWithFrame:CGRectMake(0, 40, KWIDTH, 40)];
    _screenView.backgroundColor = [UIColor grayColor];
    [self.headerView addSubview:_screenView];
    
    
    _screenButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    _screenButton1.frame = CGRectMake(0, 0, KWIDTH / 4, 40);
    [_screenButton1 setTitle:@"品牌   ·" forState:UIControlStateNormal];
    [_screenButton1 addTarget:self action:@selector(screenButton1:) forControlEvents:UIControlEventTouchUpInside];
    [_screenView addSubview:_screenButton1];
    
    
    _screenButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _screenButton2.frame = CGRectMake(KWIDTH / 4, 0, KWIDTH / 4, 40);
    [_screenButton2 setTitle:@"价格   ·" forState:UIControlStateNormal];
    [_screenButton2 addTarget:self action:@selector(screenButton2:) forControlEvents:UIControlEventTouchUpInside];
    [_screenView addSubview:_screenButton2];
    
    _screenButton3 = [UIButton buttonWithType:UIButtonTypeCustom];
    _screenButton3.frame = CGRectMake(KWIDTH / 4 * 2, 0, KWIDTH / 4, 40);
    [_screenButton3 setTitle:@"医保   ·" forState:UIControlStateNormal];
    [_screenButton3 addTarget:self action:@selector(screenButton3:) forControlEvents:UIControlEventTouchUpInside];
    [_screenView addSubview:_screenButton3];
    
    _screenButton4 = [UIButton buttonWithType:UIButtonTypeCustom];
    _screenButton4.frame = CGRectMake(KWIDTH / 4 * 3, 0, KWIDTH / 4, 40);
    [_screenButton4 setTitle:@"基本药   ·" forState:UIControlStateNormal];
    [_screenButton4 addTarget:self action:@selector(screenButton4:) forControlEvents:UIControlEventTouchUpInside];
    [_screenView addSubview:_screenButton4];
    
 
    _myScrollerView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 80, KWIDTH, KHEIGHT - 80)];
    _myScrollerView.pagingEnabled = YES;
    _myScrollerView.delegate = self;
    _myScrollerView.contentSize = CGSizeMake(KWIDTH * 3, KHEIGHT - 80);
    _myScrollerView.contentOffset = CGPointMake(0, 0);
    _myScrollerView.bounces = NO;
    _myScrollerView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_myScrollerView];
    
    _tableView1 = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT - 64 - 46 - 80) style:UITableViewStylePlain];
    _tableView1.delegate = self;
    _tableView1.dataSource = self;
    [self.myScrollerView addSubview:_tableView1];
    
    
    _tableView2 = [[UITableView alloc]initWithFrame:CGRectMake(KWIDTH, 0, KWIDTH, KHEIGHT - 64 - 46 - 80) style:UITableViewStylePlain];
    _tableView2.delegate = self;
    _tableView2.dataSource = self;
    [self.myScrollerView addSubview:_tableView2];
    _tableView3 = [[UITableView alloc]initWithFrame:CGRectMake(KWIDTH * 2, 0, KWIDTH, KHEIGHT - 64 - 46 - 80) style:UITableViewStylePlain];
    _tableView3.delegate = self;
    _tableView3.dataSource = self;
    [self.myScrollerView addSubview:_tableView3];
    // 注册
    [_tableView1 registerClass:[ClassificationTableViewCell class] forCellReuseIdentifier:@"cell"];
    [_tableView2 registerClass:[ClassificationTableViewCell class] forCellReuseIdentifier:@"cell"];
    [_tableView3 registerClass:[ClassificationTableViewCell class] forCellReuseIdentifier:@"cell"];
 
    
    
    // 品牌tableView
    _screenTableView1 = [[UITableView alloc]initWithFrame:CGRectMake(0, 80, KWIDTH, 0) style:UITableViewStylePlain];
    _screenTableView1.delegate = self;
    _screenTableView1.dataSource = self;
    [self.view addSubview:_screenTableView1];
    [_screenTableView1 registerClass:[UITableViewCell class] forCellReuseIdentifier:@"screen"];
    
    _screenTableView2 = [[UITableView alloc]initWithFrame:CGRectMake(0, 80, KWIDTH, 0) style:UITableViewStylePlain];
    _screenTableView2.delegate = self;
    _screenTableView2.dataSource = self;
    [self.view addSubview:_screenTableView2];
    [_screenTableView2 registerClass:[UITableViewCell class] forCellReuseIdentifier:@"screen"];
    
    _screenTableView3 = [[UITableView alloc]initWithFrame:CGRectMake(0, 80, KWIDTH, 0) style:UITableViewStylePlain];
    _screenTableView3.delegate = self;
    _screenTableView3.dataSource = self;
    [self.view addSubview:_screenTableView3];
    [_screenTableView3 registerClass:[UITableViewCell class] forCellReuseIdentifier:@"screen"];
    
    _screenTableView4 = [[UITableView alloc]initWithFrame:CGRectMake(0, 80, KWIDTH, 0) style:UITableViewStylePlain];
    _screenTableView4.delegate = self;
    _screenTableView4.dataSource = self;
    [self.view addSubview:_screenTableView4];
    [_screenTableView4 registerClass:[UITableViewCell class] forCellReuseIdentifier:@"screen"];
    
    [self request];
    
//    // 下拉刷新方法 不管那个页面直接加了
//    _tableView1.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        // 刷新的内容
//        [self requestOne];
//    }];
//    _tableView2.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        // 刷新的内容
//        [self requestTow];
//    }];
//    _tableView3.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        // 刷新的内容
//        [self requestThree];
//    }];
//    
//    // 上拉加载更多
//    _tableView1.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//        [self add];
//    }];
//    _tableView2.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//        [self add];
//    }];
//    _tableView3.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//        [self add];
//    }];
//    
}

- (void)request
{
    if (_number == 1)
    {
        // 感冒用药
        [_styleButton1 setTitle:@"解热阵痛" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"病毒性感冒"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"驱风祛暑" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E8%A7%A3%E7%83%AD%E9%95%87%E7%97%9B&app_key=app";
        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1, _myCount];

        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E7%97%85%E6%AF%92%E6%80%A7%E6%84%9F%E5%86%92&app_key=app";
        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string1,_index2,_myCount];
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E9%A9%B1%E9%A3%8E%E7%A5%9B%E6%9A%91&app_key=app";
        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
    }
    else if (_number == 2)
    {
        // 慢性用药
        [_styleButton1 setTitle:@"心脑血管病" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"糖尿病用药"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"肠胃用药" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E5%BF%83%E8%84%91%E8%A1%80%E7%AE%A1&app_key=app";

        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1, _myCount];
        
        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E7%B3%96%E5%B0%BF%E7%97%85&app_key=app";

        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string1,_index2,_myCount];
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E8%82%A0%E8%83%83%E7%94%A8%E8%8D%AF&app_key=app";

        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
    }else if (_number == 3)
    {
        // 家庭用药
        [_styleButton1 setTitle:@"跌打损伤" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"烧伤烫伤"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"晕车晕船" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E6%89%AD%E4%BC%A4%E6%8C%AB%E4%BC%A4%E5%86%BB%E4%BC%A4&app_key=app&cur";
        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1,_myCount];
        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E7%83%A7%E4%BC%A4%E7%83%AB%E4%BC%A4&app_key=app&cur";
        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string1,_index2,_myCount];
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E6%99%95%E8%BD%A6%E6%99%95%E8%88%B9&app_key=app&cur";
        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=20%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
    }else if (_number == 4)
    {
        // 感冒用药
        [_styleButton1 setTitle:@"解热阵痛" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"病毒性感冒"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"驱风祛暑" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E8%A7%A3%E7%83%AD%E9%95%87%E7%97%9B&app_key=app&cur";
        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1,_myCount];
        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E7%97%85%E6%AF%92%E6%80%A7%E6%84%9F%E5%86%92&app_key=app&cur";
        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5", string1,_index2,_myCount];
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E9%A9%B1%E9%A3%8E%E7%A5%9B%E6%9A%91&app_key=app&cur";
        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
    }else if (_number == 5)
    {
        // 维生素
        [_styleButton1 setTitle:@"补钙补锌" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"补钙补硒"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"复合维生素" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E8%A1%A5%E9%92%99%E8%A1%A5%E9%94%8C&app_key=app";
        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1,_myCount];
        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E8%A1%A5%E9%93%81%E8%A1%A5%E7%A1%92&app_key=app";
        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string1,_index2,_myCount];
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E5%A4%8D%E5%90%88%E7%BB%B4%E7%94%9F%E7%B4%A0&app_key=app";
        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
        
    }else if (_number == 6)
    {
        // 妇科用药
        [_styleButton1 setTitle:@"阴道炎" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"月经不调"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"痛经" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E9%98%B4%E9%81%93%E7%82%8E&app_key=app";
        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1,_myCount];
        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E6%9C%88%E7%BB%8F%E4%B8%8D%E8%B0%83&app_key=app";
        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string1,_index2,_myCount];
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E7%97%9B%E7%BB%8F&app_key=app";
        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
    }else if (_number == 7)
    {
        // 男科用药
        [_styleButton1 setTitle:@"前列腺用药" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"阳痿早泄"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"滑精遗精" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E5%89%8D%E5%88%97%E8%85%BA%E7%94%A8%E8%8D%AF&app_key=app";
        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1,_myCount];
        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E9%98%B3%E7%97%BF%E6%97%A9%E6%B3%84&app_key=app";
        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string1,_index2,_myCount];
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E6%BB%91%E7%B2%BE%E9%81%97%E7%B2%BE&app_key=app";
        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
        
    }else if (_number == 8)
    {
        // 儿科用药
        [_styleButton1 setTitle:@"小儿感冒发烧" forState:UIControlStateNormal];
        [_styleButton2 setTitle:@"小儿止咳化痰"forState:UIControlStateNormal];
        [_styleButton3 setTitle:@"小儿肠胃用药" forState:UIControlStateNormal];
        NSString *string = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E5%B0%8F%E5%84%BF%E6%84%9F%E5%86%92%E5%8F%91%E7%83%A7&app_key=app";
        _url1 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string,_index1,_myCount];
        NSString *string1 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E5%B0%8F%E5%84%BF%E6%AD%A2%E5%92%B3%E5%8C%96%E7%97%B0&app_key=app";
        _url2 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string1,_index2,_myCount];
        NSLog(@"%@",_url2);
        NSString *string2 = @"http://openapi.db.39.net/app/GetDrugsByCategory?CategoryName=%E5%B0%8F%E5%84%BF%E8%83%83%E8%82%A0%E7%94%A8%E8%8D%AF&app_key=app";
        _url3 = [NSString stringWithFormat:@"%@&curPage=%ld&limit=%ld&sign=9DFAAD5404FCB6168EA6840DCDFF39E5",string2,_index3,_myCount];
        [self requestOne];
        [self requestTow];
        [self requestThree];
    }
}

// 加载更多方法
- (void)add
{
    if (_myScrollerView.contentOffset.x == 0)
    {
        _index1++;
        if (_myCount *_index1 >= _count1)
        {
            [_tableView1.mj_footer endRefreshing];
            return;
        }
    }else if (_myScrollerView.contentOffset.x == KWIDTH)
    {
        _index2++;
        if (_myCount *_index2 >= _count2)
        {
            [_tableView2.mj_footer endRefreshing];
            return;
        }
    }else if (_myScrollerView.contentOffset.x == KWIDTH * 2)
    {
        _index3++;
        if (_myCount *_index3 >= _count3)
        {
            [_tableView3.mj_footer endRefreshing];
            return;
        }
    }
    [self request];
}


// 第一个网络请求
- (void)requestOne
{
    [RequestManager requestWithUrl:_url1 requestType:RequestTypeGET parDic:nil finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        // 只有想加载才会走
        if (_index1 > 0)
        {
            NSMutableArray *oneArray = [NSMutableArray array];
            oneArray = [ClassificationModel getData:dic];
            for (NSMutableArray *array in oneArray)
            {
                [_oneArray addObject:array];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView1 reloadData];
                [_tableView1.mj_header endRefreshing];
                [_tableView1.mj_footer endRefreshing];
            });
        }else
        {
            _oneArray = [ClassificationModel getData:dic];
            
            
            _array1 = _oneArray;
            _nameArray1 = [ClassificationModel getBrands:dic];
            _count1 = [ClassificationModel Count:dic].Count;
            [_nameArray1 insertObject:@"无限制" atIndex:0];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView1 reloadData];
                [_tableView1.mj_header endRefreshing];
                [self.screenTableView1 reloadData];
            });
        }
    } error:^(NSError *error) {
        NSLog(@"第一分类网络错误");
    }];
}

// 第二个网络请求
- (void)requestTow
{
  
    [RequestManager requestWithUrl:_url2 requestType:RequestTypeGET parDic:nil finish:^(NSData *data) {
       
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
         NSLog(@"%@ %@",dic,data);
        if (_index2 > 0)
        {
            NSMutableArray *oneArray = [NSMutableArray array];
            oneArray = [ClassificationModel getData:dic];
            for (NSMutableArray *array in oneArray)
            {
                [_towArray addObject:array];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView2 reloadData];
                [_tableView2.mj_footer endRefreshing];
                [_tableView2.mj_header endRefreshing];
            });

        }else
        {
            
            _towArray = [ClassificationModel getData:dic];
            _array2 = _towArray;
            _nameArray2 = [ClassificationModel getBrands:dic];
            _count2 = [ClassificationModel Count:dic].Count;
            [_nameArray2 insertObject:@"无限制" atIndex:0];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView2 reloadData];
                [self.screenTableView1 reloadData];
                [_tableView2.mj_header endRefreshing];
            });

        }
            } error:^(NSError *error) {
        NSLog(@"第二分类网络错误");
    }];
}

// 第三个网络请求
- (void)requestThree
{
    
    NSLog(@"%@",_url3);
    [RequestManager requestWithUrl:_url3 requestType:RequestTypeGET parDic:nil finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        if (_index3 > 0)
        {
            NSMutableArray *oneArray = [NSMutableArray array];
            oneArray = [ClassificationModel getData:dic];
            for (NSMutableArray *array in oneArray)
            {
                [_threeArray addObject:array];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView3 reloadData];
                [_tableView3.mj_footer endRefreshing];
                [_tableView3.mj_header endRefreshing];
            });
        }else
        {
            _threeArray = [ClassificationModel getData:dic];
            _nameArray3 = [ClassificationModel getBrands:dic];
            _count3 = [ClassificationModel Count:dic].Count;
            _array3 = _threeArray;
            [_nameArray3 insertObject:@"无限制" atIndex:0];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView3 reloadData];
                [self.screenTableView1 reloadData];
                [_tableView3.mj_header endRefreshing];
            });

        }
            } error:^(NSError *error) {
        NSLog(@"第二分类网络错误");
    }];
}

#pragma mark --- 点击隐藏显示方法 ---
- (void)screenButton1:(UIButton *)button
{
    _screenButton1.backgroundColor = [UIColor orangeColor];
    _screenButton2.backgroundColor = [UIColor grayColor];
    _screenButton3.backgroundColor = [UIColor grayColor];
    _screenButton4.backgroundColor = [UIColor grayColor];
    if (_screenButton1.backgroundColor == [UIColor orangeColor])
    {
        _screenTableView1.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 3);
        _screenTableView2.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView3.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView4.frame = CGRectMake(0, 80, KWIDTH, 0);
    }
    _tableViewYes1 = !_tableViewYes1;
    [UIView animateWithDuration:0.5 animations:^{
        if (_tableViewYes1 == YES)
        {
            _screenTableView1.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 3);
        }
        else
        {
            _screenTableView1.frame = CGRectMake(0, 80, KWIDTH, 0);
        }
    }];
}

- (void)screenButton2:(UIButton *)button
{
    _screenButton1.backgroundColor = [UIColor grayColor];
    _screenButton2.backgroundColor = [UIColor orangeColor];
    _screenButton3.backgroundColor = [UIColor grayColor];
    _screenButton4.backgroundColor = [UIColor grayColor];
    if (_screenButton2.backgroundColor == [UIColor orangeColor])
    {
        _screenTableView2.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 4);
        _screenTableView1.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView3.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView4.frame = CGRectMake(0, 80, KWIDTH, 0);
    }
    _tableViewYes2 = !_tableViewYes2;
    [UIView animateWithDuration:0.5 animations:^{
        if (_tableViewYes2 == YES)
        {
            _screenTableView2.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 4);
        }
        else
        {
            _screenTableView2.frame = CGRectMake(0, 80, KWIDTH, 0);
        }
    }];
}

- (void)screenButton3:(UIButton *)button
{
    _screenButton1.backgroundColor = [UIColor grayColor];
    _screenButton2.backgroundColor = [UIColor grayColor];
    _screenButton3.backgroundColor = [UIColor orangeColor];
    _screenButton4.backgroundColor = [UIColor grayColor];
    if (_screenButton3.backgroundColor == [UIColor orangeColor])
    {
        _screenTableView1.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView2.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView3.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 5);
        _screenTableView4.frame = CGRectMake(0, 80, KWIDTH, 0);
    }
    _tableViewYes3 = !_tableViewYes3;
    [UIView animateWithDuration:0.5 animations:^{
        if (_tableViewYes3 == YES)
        {
            _screenTableView3.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 5);
        }
        else
        {
            _screenTableView3.frame = CGRectMake(0, 80, KWIDTH, 0);
        }
    }];

}

- (void)screenButton4:(UIButton *)button
{
    _screenButton1.backgroundColor = [UIColor grayColor];
    _screenButton2.backgroundColor = [UIColor grayColor];
    _screenButton3.backgroundColor = [UIColor grayColor];
    _screenButton4.backgroundColor = [UIColor orangeColor];
    if (_screenButton4.backgroundColor == [UIColor orangeColor])
    {
        _screenTableView1.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView2.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView3.frame = CGRectMake(0, 80, KWIDTH, 0);
        _screenTableView4.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 5);
    }
    
    _tableViewYes4 = !_tableViewYes4;
    [UIView animateWithDuration:0.5 animations:^{
        if (_tableViewYes4 == YES)
        {
            _screenTableView4.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT / 5);
        }
        else
        {
            _screenTableView4.frame = CGRectMake(0, 80, KWIDTH, 0);
        }
    }];

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    
    if (tableView == _screenTableView1)
    {
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"screen" forIndexPath:indexPath];
        if (_myScrollerView.contentOffset.x == 0)
        {
            cell.textLabel.text = _nameArray1[indexPath.row];
        }
        else if (_myScrollerView.contentOffset.x == KWIDTH)
        {
            cell.textLabel.text = _nameArray2[indexPath.row];
        }
        else
        {
            cell.textLabel.text = _nameArray3[indexPath.row];
        }
        return cell;
        
    }else if (tableView == _screenTableView2)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"screen" forIndexPath:indexPath];

        _priceArray = @[@"无限制",@"1-20元",@"20-50元",@"100元以上"];
        cell.textLabel.text = _priceArray[indexPath.row];
        return cell;
    }else if (tableView == _screenTableView3)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"screen" forIndexPath:indexPath];

        _yibaoArray = @[@"无限制",@"医保",@"非医保"];
        cell.textLabel.text = _yibaoArray[indexPath.row];
        return cell;
    }else if (tableView == _screenTableView4)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"screen" forIndexPath:indexPath];

        _jibenyaoArray = @[@"无限制",@"基本药",@"非基本药"];
        cell.textLabel.text = _jibenyaoArray[indexPath.row];
        return cell;
    }
    
    
    ClassificationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    // 取消渲染
    cell.selectionStyle = UITableViewCellAccessoryNone;
    // cellButton点击方法
    [cell.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    // 因为复用问题 所以在这儿给tag值
    cell.button.tag = indexPath.row * 2 + 1;
    [cell.button1 addTarget:self action:@selector(buttonAction1:) forControlEvents:UIControlEventTouchUpInside];
    // 因为复用所以在这里给tag值
    cell.button1.tag = indexPath.row * 2 + 2;
    if (tableView == _tableView1)
    {
        if (_screenButton2.backgroundColor == [UIColor orangeColor])
        {
            if (_oneArray.count == 1)
            {
                
                ClassificationModel *model1 = _oneArray[indexPath.row * 2];
                [cell getModel:model1 modle2:nil];
                return cell;
            }else
            {
                //            NSLog(@"%@",_oneArray);
                ClassificationModel *model1 = _oneArray[indexPath.row * 2];
                ClassificationModel *model2 = _oneArray[indexPath.row * 2 + 1];
                [cell getModel:model1 modle2:model2];
                return cell;
            }
        }
        if (_oneArray.count == 1)
        {
            
             ClassificationModel *model1 = _oneArray[indexPath.row * 2];
            [cell getModel:model1 modle2:nil];
            return cell;
        }else
        {
//            NSLog(@"%@",_oneArray);
            ClassificationModel *model1 = _oneArray[indexPath.row * 2];
            ClassificationModel *model2 = _oneArray[indexPath.row * 2 + 1];
            [cell getModel:model1 modle2:model2];
            return cell;
        }
    }
    else if (tableView == _tableView2)
    {
        if (_towArray.count == 1)
        {
            ClassificationModel *model1 = _towArray[indexPath.row * 2];
//            NSLog(@"====%@",_towArray);
            [cell getModel:model1 modle2:nil];
            return cell;
        }else
        {
//            NSLog(@"+++++++%@",_towArray);
            ClassificationModel *model1 = _towArray[indexPath.row * 2];
            ClassificationModel *model2 = _towArray[indexPath.row * 2 + 1];
            [cell getModel:model1 modle2:model2];
            return cell;
        }
    }
    else
    {
        if (_threeArray.count == 1)
        {
            
            ClassificationModel *model1 = _threeArray[indexPath.row * 2];
            [cell getModel:model1 modle2:nil];
            return cell;
        }else
        {
            ClassificationModel *model1 = _threeArray[indexPath.row * 2];
            ClassificationModel *model2 = _threeArray[indexPath.row * 2 + 1];
            [cell getModel:model1 modle2:model2];
            return cell;
        }
    }
}

#pragma mark --- cell点击方法 ---
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 一进来清除数组 使他每次都是新的
    [_newoneArray removeAllObjects];
    [_newtowArray removeAllObjects];
    [_newthreeArray removeAllObjects];
    NSString *string = _nameArray1[indexPath.row];
    NSString *string2 = _nameArray2[indexPath.row];
    NSString *string3 = _nameArray3[indexPath.row];
    
    // 品牌筛选
    if (tableView == _screenTableView1)
    {
        if (_styleButton1.backgroundColor == [UIColor greenColor])
        {
            
            for (ClassificationModel *model in _array1)
            {
                if ([string isEqualToString:model.refdrugbrandname])
                {
                    [_newoneArray addObject:model];
                }
            }
            _oneArray = _newoneArray;
            if ([string isEqualToString:@"无限制"])
            {
                _oneArray = _array1;
            }
            
//            NSLog(@"===%@",_oneArray);
//            NSLog(@"---%@",_newoneArray);
            [self.tableView1 reloadData];
            if (_newoneArray.count == 0)
            {
                return;
            }
        }
    }
    
    if (tableView == _screenTableView1)
    {
        if (_styleButton2.backgroundColor == [UIColor greenColor])
        {
            for (ClassificationModel *model in _array2)
            {
                if ([string2 isEqualToString:model.refdrugbrandname])
                {
                    [_newtowArray addObject:model];
                }
            }
            _towArray = _newtowArray;
            if ([string2 isEqualToString:@"无限制"])
            {
                _towArray = _array1;
            }
//            NSLog(@"%@",_towArray);
            [self.tableView2 reloadData];
            if (_newtowArray.count == 0)
            {
                return;
            }
        }
    }
    
    
    if (tableView == _screenTableView1)
    {
        if (_styleButton3.backgroundColor == [UIColor greenColor])
        {
            for (ClassificationModel *model in _array3)
            {
                if ([string3 isEqualToString:model.refdrugbrandname])
                {
                    [_newthreeArray addObject:model];
                }
            }
            _threeArray = _newthreeArray;
            if ([string2 isEqualToString:@"无限制"])
            {
                _threeArray = _array3;
            }
            NSLog(@"%@",_threeArray);
            [self.tableView3 reloadData];
            if (_newthreeArray.count == 0)
            {
                return;
            }
        }
    }
    
    [_newpriceArray1 removeAllObjects];
    // 价格筛选
    if (tableView == _screenTableView2)
    {
        if (_styleButton1.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array1)
                {
                    if (model.avgprice >= 1 && model.avgprice <= 20)
                    {
                        
                        [_newpriceArray1 addObject:model];
                    }
                }
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array1)
                {
                    if (model.avgprice >= 20 && model.avgprice <= 50)
                    {
                        
                        [_newpriceArray1 addObject:model];
                    }
                }
            }
            if (indexPath.row == 3)
            {
                for (ClassificationModel *model in _array1)
                {
                    if (model.avgprice >= 100)
                    {
                        
                        [_newpriceArray1 addObject:model];
                    }
                }
            }
            _oneArray = _newpriceArray1;
            if (indexPath.row == 0)
            {
                _oneArray = _array1;
            }
            [self.tableView1 reloadData];
            if (_oneArray.count == 0)
            {
                return;
            }
        }
//        NSLog(@"%ld",_oneArray.count);
//        NSLog(@"%ld",_newpriceArray1.count);
        
    }
    
    [_newpriceArray2 removeAllObjects];
    if (tableView == _screenTableView2)
    {
        if (_styleButton2.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array2)
                {
                    if (model.avgprice >= 1 && model.avgprice <= 20)
                    {
                        
                        [_newpriceArray2 addObject:model];
                    }
                }
            }
            
            if (indexPath.row == 0)
            {
                _towArray = _array2;
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array2)
                {
                    if (model.avgprice >= 20 && model.avgprice <= 50)
                    {
                        
                        [_newpriceArray2 addObject:model];
                    }
                }
            }
            if (indexPath.row == 3)
            {
                for (ClassificationModel *model in _array2)
                {
                    if (model.avgprice >= 100)
                    {
                        
                        [_newpriceArray2 addObject:model];
                    }
                }
            }
            _towArray = _newpriceArray2;
            [self.tableView2 reloadData];
            if (_towArray.count == 0)
            {
                return;
            }

        }
    }
    
    [_newpriceArray3 removeAllObjects];
    if (tableView == _screenTableView2)
    {
        if (_styleButton3.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array3)
                {
                    if (model.avgprice >= 1 && model.avgprice <= 20)
                    {
                        
                        [_newpriceArray3 addObject:model];
                    }
                }
            }
            
            if (indexPath.row == 0)
            {
                _threeArray = _array3;
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array3)
                {
                    if (model.avgprice >= 20 && model.avgprice <= 50)
                    {
                        
                        [_newpriceArray3 addObject:model];
                    }
                }
            }
            if (indexPath.row == 3)
            {
                for (ClassificationModel *model in _array3)
                {
                    if (model.avgprice >= 100)
                    {
                        
                        [_newpriceArray3 addObject:model];
                    }
                }
                _threeArray = _newpriceArray3;
            }
            
            [self.tableView3 reloadData];
            if (_threeArray.count == 0)
            {
                return;
            }
        }
    }
    
    [_newyibaoArray1 removeAllObjects];
    // 医保筛选
    if (tableView == _screenTableView3)
    {
        if (_styleButton1.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array1)
                {
                    // 非0是医保
                    if (model.medcare != 0)
                    {
                        
                        [_newyibaoArray1 addObject:model];
                    }
                }
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array1)
                {
                    // 0是医保
                    if (model.medcare == 0)
                    {
                        
                        [_newyibaoArray1 addObject:model];
                    }
                }
            }
            _oneArray = _newyibaoArray1;
            
            if (indexPath.row == 0)
            {
                    _oneArray = _array1;
            }
            [self.tableView1 reloadData];
            if (_oneArray.count == 0)
            {
                return;
            }
        }
    }

    
    [_newyibaoArray2 removeAllObjects];
    if (tableView == _screenTableView3)
    {
        if (_styleButton2.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array2)
                {
                    // 非0是医保
                    if (model.medcare != 0)
                    {
                        
                        [_newyibaoArray2 addObject:model];
                    }
                }
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array2)
                {
                    // 0是医保
                    if (model.medcare == 0)
                    {
                        
                        [_newyibaoArray2 addObject:model];
                    }
                }
            }
            _towArray = _newyibaoArray2;
            
            if (indexPath.row == 0)
            {
                _towArray = _array2;
            }
            [self.tableView2 reloadData];
            if (_towArray.count == 0)
            {
                return;
            }
        }
        
    }
    
    
    [_newyibaoArray3 removeAllObjects];
    if (tableView == _screenTableView3)
    {
        if (_styleButton3.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array3)
                {
                    // 非0是医保
                    if (model.medcare != 0)
                    {
                        
                        [_newyibaoArray3 addObject:model];
                    }
                }
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array3)
                {
                    // 0是医保
                    if (model.medcare == 0)
                    {
                        
                        [_newyibaoArray3 addObject:model];
                    }
                }
            }
            _threeArray = _newyibaoArray3;
            
            if (indexPath.row == 0)
            {
                _threeArray = _array3;
            }
            [self.tableView3 reloadData];
            if (_threeArray.count == 0)
            {
                return;
            }
        }
    }

    // 基本药
    [_newjibenyaoArray1 removeAllObjects];
    if (tableView == _screenTableView4)
    {
        if (_styleButton1.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array1)
                {
                    if (1 == model.basemed)
//                        NSLog(@"%ld",model.basemed);
                    {
                        
                        [_newjibenyaoArray1 addObject:model];
                    }
                }
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array1)
                {
                    
                    if (1 != model.basemed)
                    {
                        
                        [_newjibenyaoArray1 addObject:model];
                    }
                }
            }
            _oneArray = _newjibenyaoArray1;
            
            if (indexPath.row == 0)
            {
                _oneArray = _array1;
            }
            [self.tableView1 reloadData];
            if (_oneArray.count == 0)
            {
                return;
            }
        }
    }
    
    [_newjibenyaoArray2 removeAllObjects];
    if (tableView == _screenTableView4)
    {
        if (_styleButton2.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array2)
                {
                    if (1 == model.basemed)
                    {
                        
                        [_newjibenyaoArray2 addObject:model];
                    }
                }
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array2)
                {
                    
                    if (1 != model.basemed)
                    {
                        
                        [_newjibenyaoArray2 addObject:model];
                    }
                }
            }
            _towArray = _newjibenyaoArray2;
            
            if (indexPath.row == 0)
            {
                _towArray = _array2;
            }
            [self.tableView2 reloadData];
            if (_towArray.count == 0)
            {
                return;
            }
        }
    }
    
    [_newjibenyaoArray3 removeAllObjects];
    if (tableView == _screenTableView4)
    {
        if (_styleButton3.backgroundColor == [UIColor greenColor])
        {
            if (indexPath.row == 1)
            {
                for (ClassificationModel *model in _array3)
                {
                    if (1 == model.basemed)
                        NSLog(@"%ld",model.basemed);
                    {
                        
                        [_newjibenyaoArray3 addObject:model];
                    }
                }
            }
            if (indexPath.row == 2)
            {
                for (ClassificationModel *model in _array3)
                {
                    
                    if (1 != model.basemed)
                    {
                        
                        [_newjibenyaoArray3 addObject:model];
                    }
                }
            }
            _threeArray = _newjibenyaoArray3;
            
            if (indexPath.row == 0)
            {
                _threeArray = _array3;
            }
            [self.tableView3 reloadData];
            if (_threeArray.count == 0)
            {
                return;
            }
        }
    }
}




#pragma mark --- 返回行数 ---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == _screenTableView1)
    {
        return _nameArray1.count;
    }else if (tableView == _screenTableView2)
    {
        return 4;
    }else if (tableView == _screenTableView3)
    {
        return 3;
    }else if (tableView == _screenTableView4)
    {
        return 3;
    }
    
    if (tableView == _tableView1)
    {
 
            return _oneArray.count / 2;
        
    }
    else if (tableView == _tableView2)
    {
        if (_towArray.count == 1)
        {
            return 1;
        }
        return _towArray.count / 2;
    }
    else
    {
        return _threeArray.count / 2;
    }
}

#pragma mark --- styleButton方法 ---
- (void)styleButton:(UIButton *)button
{
    if (button == _styleButton1)
    {
        [_myScrollerView setContentOffset:CGPointMake(0, 0)];
        [self requestOne];
    }else if (button == _styleButton2)
    {
        [_myScrollerView setContentOffset:CGPointMake(KWIDTH, 0)];
        [self requestTow];
    }else
    {
        [_myScrollerView setContentOffset:CGPointMake(KWIDTH * 2, 0)];
        [self requestThree];
    }
    [UIView animateWithDuration:0.5 animations:^{
        _lView.frame = CGRectMake((KWIDTH - 30) / 3 * _myScrollerView.contentOffset.x / KWIDTH, 39, (KWIDTH - 30) / 3, 1);
        if (_myScrollerView.contentOffset.x == 0)
        {
            _styleButton1.backgroundColor = [UIColor greenColor];
            _styleButton2.backgroundColor = [UIColor yellowColor];
            _styleButton3.backgroundColor = [UIColor yellowColor];
        }else if (_myScrollerView.contentOffset.x == KWIDTH)
        {
            _styleButton1.backgroundColor = [UIColor yellowColor];
            _styleButton2.backgroundColor = [UIColor greenColor];
            _styleButton3.backgroundColor = [UIColor yellowColor];
        }else
        {
            _styleButton1.backgroundColor = [UIColor yellowColor];
            _styleButton2.backgroundColor = [UIColor yellowColor];
            _styleButton3.backgroundColor = [UIColor greenColor];
        }
        
    }];
}

#pragma mark --- 点击隐藏筛选 ---
- (void)showAction:(UIButton *)button
{
    _show = !_show;
    if (_show == NO)
    {
        [UIView animateWithDuration:0.5 animations:^{
            _screenView.frame = CGRectMake(0, 40, KWIDTH, 40);
            _screenButton1.frame = CGRectMake(0, 0, KWIDTH / 4, 40);
             _screenButton2.frame = CGRectMake(KWIDTH / 4, 0, KWIDTH / 4, 40);
            _screenButton3.frame = CGRectMake(KWIDTH / 4 * 2, 0, KWIDTH / 4, 40);
             _screenButton4.frame = CGRectMake(KWIDTH / 4 * 3, 0, KWIDTH / 4, 40);
            _myScrollerView.frame = CGRectMake(0, 80, KWIDTH, KHEIGHT - 80);
            // YES为隐藏
            _screenTableView1.hidden = NO;
            _screenTableView2.hidden = NO;
            _screenTableView3.hidden = NO;
            _screenTableView4.hidden = NO;
        }];
       
        [_screenButton1 setTitle:@"品牌   ·" forState:UIControlStateNormal];
       
        [_screenButton2 setTitle:@"价格   ·" forState:UIControlStateNormal];
        
        [_screenButton3 setTitle:@"医保  ·" forState:UIControlStateNormal];
       
        [_screenButton4 setTitle:@"基本药 ·" forState:UIControlStateNormal];

        
    }
    else
    {
        [UIView animateWithDuration:0.5 animations:^{
            _screenView.frame = CGRectMake(0, 40, KWIDTH, 0);
            _screenButton1.frame = CGRectMake(0, 0, KWIDTH / 4, 0);
             _screenButton2.frame = CGRectMake(KWIDTH / 4, 0, KWIDTH / 4, 0);
             _screenButton3.frame = CGRectMake(KWIDTH / 4 * 2, 0, KWIDTH / 4, 0);
            _screenButton4.frame = CGRectMake(KWIDTH / 4 * 3, 0, KWIDTH / 4, 0);
            _myScrollerView.frame = CGRectMake(0, 40, KWIDTH, KHEIGHT - 80);
            // YES为隐藏
            _screenTableView1.hidden = YES;
            _screenTableView2.hidden = YES;
            _screenTableView3.hidden = YES;
            _screenTableView4.hidden = YES;
        }];
        
        [_screenButton1 setTitle:@"" forState:UIControlStateNormal];
        [_screenButton2 setTitle:@"" forState:UIControlStateNormal];
        [_screenButton3 setTitle:@"" forState:UIControlStateNormal];
        [_screenButton4 setTitle:@"" forState:UIControlStateNormal];      
    }
}

#pragma mark --- scrollerView结束滚动方法 ---
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    // 如果是tableView退出
    if ([scrollView isMemberOfClass:[UITableView class]])
    {
        return;
    }
    [UIView animateWithDuration:0.5 animations:^{
        _lView.frame = CGRectMake((KWIDTH - 30) / 3 * _myScrollerView.contentOffset.x / KWIDTH, 39, (KWIDTH - 30) / 3, 1);
        if (_myScrollerView.contentOffset.x == 0)
        {
            _styleButton1.backgroundColor = [UIColor greenColor];
            _styleButton2.backgroundColor = [UIColor yellowColor];
            _styleButton3.backgroundColor = [UIColor yellowColor];
            [self requestOne];
        }else if (_myScrollerView.contentOffset.x == KWIDTH)
        {
            _styleButton1.backgroundColor = [UIColor yellowColor];
            _styleButton2.backgroundColor = [UIColor greenColor];
            _styleButton3.backgroundColor = [UIColor yellowColor];
            [self requestTow];
        }else
        {
            _styleButton1.backgroundColor = [UIColor yellowColor];
            _styleButton2.backgroundColor = [UIColor yellowColor];
            _styleButton3.backgroundColor = [UIColor greenColor];
            [self requestThree];
        }
    }];
}

#pragma mark --- 第一列cell ---
- (void)buttonAction:(UIButton *)button
{
    PharmacyViewController *pharmacy = [[PharmacyViewController alloc]init];
    _row = button.tag;
    pharmacy.towBool = 2;
    if (_myScrollerView.contentOffset.x == 0)
    {
        ClassificationModel *model = _oneArray[_row - 1];
        pharmacy.classModel = model;
    }else if (_myScrollerView.contentOffset.x == KWIDTH)
    {
        ClassificationModel *model = _towArray[_row - 1];
        pharmacy.classModel = model;
    }else
    {
        ClassificationModel *model = _threeArray[_row - 1];
        pharmacy.classModel = model;
    }
    //    NSLog(@"%ld",_row);
    //    NSLog(@"%@",pharmacy.HomeImageModel.ID);
    [self.navigationController pushViewController:pharmacy animated:YES];
}

#pragma mark --- 第二列cell ---
- (void)buttonAction1:(UIButton *)button
{
    PharmacyViewController *pharmacy = [[PharmacyViewController alloc]init];
    _row = button.tag;
    pharmacy.towBool = 2;
    if (_myScrollerView.contentOffset.x == 0)
    {
        ClassificationModel *model = _oneArray[_row - 1];
        pharmacy.classModel = model;
    }else if (_myScrollerView.contentOffset.x == KWIDTH)
    {
        ClassificationModel *model = _towArray[_row - 1];
        pharmacy.classModel = model;
        
    }else
    {
        ClassificationModel *model = _threeArray[_row - 1];
        pharmacy.classModel = model;
    }
    [self.navigationController pushViewController:pharmacy animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == _tableView1 || tableView == _tableView2 || tableView == _tableView3)
    {
        return 160;
    }
    return 44;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
